import router from '~/router'
import { getToken } from './composables/auth'
import { toast } from './composables/util'
import store from './store'
import {login} from './api/manager.js'
router.beforeEach(async (to,from,next)=>{
    console.log("全局前置守卫")
    const token  = getToken()
    //没有token且去的不是登录页
    if(!token&&to.path!="/login"){
        toast("请先登录","error")
        return next({
            path:"/login"
        })
    }
    if(token&&to.path=="/login"){
        toast("请勿重复登录","error")
        return next({
            path:from.path?from.path:"/"
        })
    }
    if(token){
        await store.dispatch("getinfo")
    }
    next()
})